﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenCvSharp;


namespace RecognitionNumbers
{
    public class Binarization : Filter
    {
        private int thresholdValuse = 100;

        public int threshold
        {
            get
            {
                return thresholdValuse;
            }
            set
            {
                if (original != null)
                    convert(original, value);
                else
                    thresholdValuse = value;
            }
        }

        public void convert(IplImage image, int threshold)
        {
            original = image;
            thresholdValuse = threshold;
            transformed = new IplImage(original.Size, BitDepth.U8, 1);
            Cv.Threshold(original, transformed, thresholdValuse, 255, ThresholdType.Binary);
        }

        public override OpenCvSharp.IplImage input
        {
            get
            {
                return original;
            }
            set
            {
                transformed = new IplImage(original.Size, BitDepth.U8, 1);
                Cv.Threshold(value, transformed, thresholdValuse, 255, ThresholdType.Binary);
            }
        }

        public Binarization(IplImage image, int threshold)
        {
            original = image;
            thresholdValuse = threshold;
            transformed = new IplImage(original.Size, BitDepth.U8, 1);
            Cv.Threshold(original, transformed, thresholdValuse, 255, ThresholdType.Binary);
        }
    }
}
